package threadcreate01;

public class thread04 {
    //俩个线程交替打印奇偶数
    public static void main(String[] args) {
        tt tt = new tt();
        new Thread(tt,"张大力").start();
        new Thread(tt,"吴霖芳").start();
        new Thread(tt,"王大锤").start();
    }
    public  static class tt implements Runnable {
        private static int i = 100;
        @Override
        public void run() {
            while (i > 0) {
                sale();
                try {
                    Thread.sleep(10);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        }
        private synchronized void sale()
        {
            if(i>0)
            {
                System.out.println(Thread.currentThread().getName()+"正在出售第"+i+"张票");
                i--;
            }
        }
    }
}
